$(function () {
  var url = location.href
  console.log(location.href);
  var id = url.split('=')[1]
  console.log(id);
  $.ajax({
    type: 'get',
    url: '/product/queryProductDetail',
    data: { id },
    dataType: 'json',
    success: function (res) {
      console.log(res)
      $('.mui-scroll').html(template('tmp', res))//轮播图初始化
      var gallery = mui('.mui-slider');
      gallery.slider({
        interval: 1000,//自动轮播周期，若为0则不自动播放，默认为0；
      });
      mui($('.mui-numbox')).numbox()//添加数量初始化
    }
  })

  var size = ''
  $('.mui-scroll').on('click', '.lt-size span', function () {
    $(this).addClass('sbgc').siblings().removeClass('sbgc')
    size = $(this).text()
  })


  $('.btn-cart').click(function () {
    var num = $('.btn-num').val()


   
    $.ajax({
      type: 'post',
      url: '/cart/addCart',
      data: {
        productId:id,
        num,
        size,
      },
      dataType: 'json',
      success: function (res) {
        console.log(res)
        if(res.success){
          location.href='cart.html'
        }else{
          var site = location.href
          location.href = 'login.html?url='+site
        }

      }
    })

    
  })


})